class User {
  final String id;
  final String username;
  final String password;
  final String nickname;
  final String avatar;
  final String birth;
  final String signature;
  final List<String> follow;

  User({
    required this.id,
    required this.username,
    required this.password,
    required this.nickname,
    required this.avatar,
    required this.birth,
    required this.signature,
    required this.follow,
  });

  // 从JSON转换为User对象
  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      id: json['id'] ?? '',
      username: json['username'] ?? '',
      password: json['password'] ?? '',
      nickname: json['nickname'] ?? '',
      avatar: json['avatar'] ?? '',
      birth: json['birth'] ?? '',
      signature: json['signature'] ?? '',
      follow: List<String>.from(json['follow'] ?? []),
    );
  }

  // 将User对象转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'username': username,
      'password': password,
      'nickname': nickname,
      'avatar': avatar,
      'birth': birth,
      'signature': signature,
      'follow': follow,
    };
  }

  // 创建User的副本并更新部分属性
  User copyWith({
    String? id,
    String? username,
    String? password,
    String? nickname,
    String? avatar,
    String? birth,
    String? signature,
    List<String>? follow,
  }) {
    return User(
      id: id ?? this.id,
      username: username ?? this.username,
      password: password ?? this.password,
      nickname: nickname ?? this.nickname,
      avatar: avatar ?? this.avatar,
      birth: birth ?? this.birth,
      signature: signature ?? this.signature,
      follow: follow ?? this.follow,
    );
  }
} 